/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Business;

import java.util.List;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author Storm^^Rain
 */
public class Products_MD extends AbstractTableModel {

    private List<Product_BS> products;
    private final String columnsName[] = {"Code", "Name", "Type", "Expiry Date", "Quantity" ,"Sell Price"};
    private final Class columnsClass[] = {Integer.class, String.class, String.class, String.class,Integer.class,Float.class};
    
    public Products_MD(List<Product_BS> products) {
        this.products = products;
    }
    
    public int getRowCount() {
        return products.toArray().length;
    }

    public int getColumnCount() {
        return columnsName.length;
    }

    public Object getValueAt(int rowIndex, int columnIndex) {
        switch (columnIndex) {
            case 0:
                return products.get(rowIndex).getpCode();
            
            case 1:
                return products.get(rowIndex).getpName();
            
            case 2:
                return products.get(rowIndex).getpType();
             
            case 3:
                return products.get(rowIndex).getpExpiryDate();

            case 4 :
                return products.get(rowIndex).getpQuantity();

            case 5:
                return products.get(rowIndex).getpSellPrice();

            default:
                return null;
                                  
        }
    }
    @Override
    public String getColumnName(int iCol) {
        return columnsName[iCol];
    }

    @Override
    public Class getColumnClass(int iCol) {
        return columnsClass[iCol];
    }
    public Product_BS getProduct(int rowIndex) {
        return products.get(rowIndex);
    }

    public void insertProduct(Product_BS product){
        fireTableDataChanged();
    }

    public void updateProduct(Product_BS product) {
        fireTableDataChanged();
    }
    public void deleteProduct(Product_BS product) {
        products.remove(product);
        fireTableDataChanged();
    }
}
